import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useImgPreviewStore = defineStore('image', () => {
    // 图片预览链接
    const previewUrl = ref('');
    // 图片预览是否显示
    const isShowing = ref(false);

    /**
     * 开启图片预览
     * @param url 图片链接
     */
    const show = (url: string) => {
        previewUrl.value = url
        isShowing.value = true
    }
    /**
     * 关闭图片预览
     */
    const close = () => {
        isShowing.value = false
        previewUrl.value = ''
    }

    return {
        previewUrl,
        isShowing,
        show,
        close,
    }
})